package com.example.myapplication.util

import android.app.Activity
import android.content.Context
import android.graphics.Color
import android.view.View
import android.widget.TextView
import com.bigkoo.pickerview.builder.OptionsPickerBuilder
import com.bigkoo.pickerview.listener.OnOptionsSelectListener
import com.example.myapplication.R

object SelectUtils {
    fun showSelectPicker(c: Context, target: TextView, selects:ArrayList<String>, callback:((postion:Int)->Unit)?=null, outSideCancelable:Boolean?=true){
        var selectedIndex=0
        if (target.text.toString().isNotEmpty()){
            //有选中值
            val toString = target.text.toString()
            selectedIndex = selects.indexOf(toString)
        }
        val picker= OptionsPickerBuilder(c,object : OnOptionsSelectListener {
            override fun onOptionsSelect(options1: Int, options2: Int, options3: Int, v: View?) {
                target.text=selects[options1]
                callback?.invoke(options1)
            }

        })  .setSubmitColor(Color.parseColor("#ebb800"))
            .setCancelColor(Color.parseColor("#aaaaaa"))
            .setSelectOptions(selectedIndex)
            .setOutSideCancelable(outSideCancelable?:true)
            .build<String>()

        picker.setPicker(selects)
        picker.show()

    }
}